package com.scl.springtalis.controller;

import com.scl.springtalis.polo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class CookieController {
    @GetMapping("c1")
    public Result cookie1(HttpServletResponse response) {
        response.addCookie(new Cookie("name","csl"));
        return Result.success();
    }

    @GetMapping("c2")
    public Result cookie2(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("name")) {
                System.out.println(cookie.getValue());
            }
        }
        return Result.success();
    }
}
